<template>
  <div>
    <div v-if="!hasData" class="tips">暂无问答</div>
    <div class="sw" v-if="hasData">
        <el-table
          :data="tableData"
          style="width: 100%"
          @row-click="goTo">
          <el-table-column
            prop="questionPoint"
            label="积分"
            width="100">
          </el-table-column>
          <el-table-column
            prop="content"
            label="问题"
            :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column
            prop="questionResult"
            label="结果"
            width="100"
            :formatter="formatterBanner">
          </el-table-column>
        </el-table>
    <div class="block" v-show="pages!== 10">
      <el-pagination
        layout="prev, pager, next"
        :total="pages"
        :current-page.sync="currentPage"
        @current-change="changePage">
      </el-pagination>
    </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'pcQuestion',
  data () {
    return {
      tableData: '',
      pages: 10,
      currentPage: 1,
      hasData: false
    }
  },
  mounted: function () {
    this.getData(1)
  },
  methods: {
    getData (page) {
      this.http.get(this.ports.personalCenter.member.question + '?page=' + page,
        res => {
          if (res.status === 200) {
            let data = res.data.result
            if (data.code === 200) {
              this.tableData = data.msg
              this.pages = data.pages * 10
              this.hasData = true
            } else if (data.code === 1 || data.code === -1) {
              this.hasData = false
            }
          } else if (res.status === 401) {
            this.$router.push('/')
          } else {
            console.log(res)
          }
        })
    },
    changePage () {
      this.getData(this.currentPage)
    },
    formatterBanner: function (row, column, cellValue) {
      if (cellValue === '0') {
        return '未解决'
      } else {
        return '已解决'
      }
    },
    goTo (row) {
      let routeUrl = this.$router.resolve({
        path: '/reply',
        query: {
          qid: row.classNo,
          type: 1
        }
      })
      window.open(routeUrl.href, '_blank')
    }
  }
}
</script>

<style  lang="scss" scoped>
  .block{
    padding: 0;
    margin: 50px 0 100px 0;
    text-align: center;
  }
  .tips {
    margin-top: 100px;
    color: #5e5e5e;
  }
  .sw {
    margin-bottom: 100px;
  }
</style>
